package com.vf.admin.client.controller.ip;

import cn.hutool.core.util.ObjectUtil;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.service.AppIpAuthService;
import com.vf.admin.common.entity.Result;
import com.vf.admin.miaodong.entity.AppIpAuth;
import com.vf.admin.utils.ip.IpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : NemoMeng
 * @Date 2023/12/28 17:30
 */
@Controller
@RequestMapping(value = "/api/white")
public class IpWitheController extends ClientBaseController {

    @Resource
    private AppIpAuthService appIpAuthService;

    //审核地址
    String test = "http://uaitest.nhfaqw.com";
    //正式
    String prod = "http://api.ptszyxx.com/";

    @RequestMapping("/reqAddress")
    @ResponseBody
    public Result reqAddress() {

        String ipAddress = IpUtils.getIpAddress(request);
        System.out.println("ipAddress"+ipAddress);

        //如果为空去审核
        if (ObjectUtil.isEmpty(ipAddress)) {
            Map<String, String> map1 = new HashMap<>();
            map1.put("url", test);
            map1.put("open","1");
            return this.sucessJSON(map1);
        } else {
            AppIpAuth ip = appIpAuthService.getIp(ipAddress);
            if (ObjectUtil.isNotEmpty(ip)) {
                Map<String, String> map2 = new HashMap<>();
                map2.put("url", test);
                map2.put("open","1");
                return this.sucessJSON(map2);

            } else {
                Map<String, String> map3 = new HashMap<>();
                map3.put("url", prod);
                map3.put("open","0");
                return this.sucessJSON(map3);
            }
        }
    }

    @RequestMapping("/test")
    public void test() {
        String ipAddress = IpUtils.getIpAddress(request);
        System.out.println("test"+ipAddress);
        AppIpAuth ip = appIpAuthService.getIp(ipAddress);
        System.out.println("AppIpAuth"+ip);

    }
}
